package com.dm.cosdemo;

import com.tencent.qcloud.core.auth.BasicLifecycleCredentialProvider;

import com.tencent.qcloud.core.auth.QCloudLifecycleCredentials;
import com.tencent.qcloud.core.auth.SessionQCloudCredentials;
import com.tencent.qcloud.core.common.QCloudClientException;

public class CosSessionCredentialProvider extends BasicLifecycleCredentialProvider {

    private String tmpSecretId;

    private String tmpSecretKey;

    private String sessionToken;

    private Long startTime;

    private Long expiredTime;

    /**
     * 获取临时秘钥凭证
     *
     * @param tmpSecretId  临时Id
     * @param tmpSecretKey 临时key
     * @param sessionToken 临时Token
     * @param startTime    开始时间
     * @param expiredTime  过期时间
     * @return
     */
    public CosSessionCredentialProvider(String tmpSecretId, String tmpSecretKey, String sessionToken, Long startTime, Long expiredTime) {
        this.tmpSecretId = tmpSecretId;
        this.tmpSecretKey = tmpSecretKey;
        this.sessionToken = sessionToken;
        this.startTime = startTime;
        this.expiredTime = expiredTime;
    }

    @Override
    protected QCloudLifecycleCredentials fetchNewCredentials() throws QCloudClientException {
        return new SessionQCloudCredentials(tmpSecretId, tmpSecretKey, sessionToken, startTime, expiredTime);

    }
}
